//
// Created by 66477 on 2022/9/28.
//

#ifndef DATA_STRUCTURE_CTRLUTIL_H
#define DATA_STRUCTURE_CTRLUTIL_H

#include "q1/List4_1.h"
#include "q1/Stack4_1.h"
#include "q2/Stack4_2.h"
#include "q3/Queue4_3.h"

class CtrlUtil {
public:
    CtrlUtil *start() {
        while (true) {
            cout << "(1-3)Which question to test? :";
            int i;
            cin >> i;
            switch (i) {
                case 1:
                    cout << "(question1)" << endl;
                    q1();
                    break;
                case 2:
                    cout << "(question2)" << endl;
                    q2();
                    break;
                case 3:
                    cout << "(question3)" << endl;
                    q3();
                    break;
                default:
                    return this;
            }
            cout << "-------------" << endl;
        }
    }

    void q1() {
        cout << "string:" << endl;
        string s;
        cin >> s;

        List4_1 *l = new List4_1(s);
        l->print();
        Stack4_1 *stack = new Stack4_1(l);
        cout << "Is symmetrical : " << stack->linkIsSymmetries() << endl;
    }

    void q2() {
        cout << "string:" << endl;
        string s;
        cin >> s;

        Stack4_2 *stack = new Stack4_2();
        cout << "Arithmetic expressions legal : " << stack->Analysis(s) << endl;
    }

    void q3() {
        Queue4_3 *q = new Queue4_3();
        int i;
        while (true) {
            cout << "input num (1)push,(2)pop,(3)free,(4)print,(5)back:";
            cin >> i;
            if (i == 1) {
                cout << "[push] string:" << endl;
                string s;
                cin >> s;
                for (int j = 0; j < s.length(); ++j) {
                    q->push(s[j]);
                }
                cout << "[print]" << endl;
                q->print();
            } else if (i == 2) {
                cout << "[pop] num int:" << endl;
                int n;
                cin >> n;
                while (n--) {
                    q->pop();
                }
                cout << "[print]" << endl;
                q->print();
            } else if (i == 3) {
                cout << "[free]" << endl;
                q->free();
            } else if (i == 4) {
                cout << "[print]" << endl;
                q->print();
            } else {
                delete q;
                break;
            }
        }
    }
};

#endif //DATA_STRUCTURE_CTRLUTIL_H
